package org.serverct.finalfight.stat.gui;

import com.sun.istack.internal.NotNull;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.serverct.finalfight.stat.IPlayer;
import org.serverct.finalfight.stat.StatManager;

import java.util.Arrays;

public class InfoGui {
    public static int[] slots = new int[]{0, 2, 4, 6, 8};

    public static Inventory generateInventory(Player player) {
        Inventory inv = Bukkit.createInventory(new InfoGuiHolder(), 9, "我的战绩");
        for (int i : slots) {
            inv.setItem(i, generateItem(Material.GRAY_STAINED_GLASS_PANE, "§7 "));
        }
        IPlayer stat = StatManager.stats.get(player.getUniqueId());
        inv.setItem(1, generateItem(Material.BIRCH_SIGN, "§b参赛统计",
                "§7- 总计: §a" + stat.played + "§7 场"
                , "§7- 胜利: §a" + stat.won + "§7 场"
                , "§7- 胜率: §a" + String.format("%.2f", stat.getWinRate() * 100) + "%"));
        inv.setItem(3, generateItem(Material.SKELETON_SKULL, "§b赛内统计",
                "§7- 击杀: §a" + stat.kill + "§7 人"
                , "§7- 死亡: §a" + stat.death + "§7 人"
                , "§7- K/D: §a" + String.format("%.2f", stat.getKDQuation() * 100) + "%"));
        inv.setItem(5, generateItem(Material.MAP, "§b事件统计",
                "§7- 点击以在聊天栏查看事件统计"));
        inv.setItem(7, generateItem(Material.BIRCH_SIGN, "§b作者信息",
                "§7- HadesGame-Frabic By Miaolio",
                "§7- HadesGame-Bukkit By HamsterYDS"));
        return inv;
    }

    public static ItemStack generateItem(Material type, String name, String... lore) {
        ItemStack item = new ItemStack(type);
        ItemMeta meta = item.getItemMeta();
        meta.setDisplayName(name);
        meta.setLore(Arrays.asList(lore));
        item.setItemMeta(meta);
        return item;
    }

    public static class InfoGuiHolder implements InventoryHolder {
        @Override
        @NotNull
        public Inventory getInventory() {
            return null;
        }
    }
}
